/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package logic;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JOptionPane;

/**
 *
 * @author HoangNam
 */
public class ValidateEmployee {

    private Pattern pattern;
    private Matcher matcher;

    private static final String Email_Pattern = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
    private static final String FullName_Pattern = "[A-Za-z0-9]";
            
            
    public ValidateEmployee() {
        
    }
    
    public boolean validate(String username,String employeeName,String password,String email,String birthday,int gender,String address,int deptId,int roleId,int managerId,String image){
        if(!validateEmail(email)){
            JOptionPane.showMessageDialog(null, "Email not valid", "Warning", JOptionPane.WARNING_MESSAGE);
            return false;
        }else if(!validateFullName(employeeName)){
            return false;
        }else if(!validateUserName(username)){
            return false;
        }else if(!validatePassword(password)){
            return false;
        }else if(!validateBirthday(birthday)){
            return false;
        }else if(!validateGender(gender)){
            return false;
        }
        return true;
    }
    
    public boolean validateEmail(final String email){
            pattern = Pattern.compile(Email_Pattern);
            matcher = pattern.matcher(email);
            return matcher.matches();
    }
    
    public boolean validateFullName(String fullName){
        if(fullName.length() < 5 || fullName.length() > 20){
            JOptionPane.showMessageDialog(null, "Full name must than 5 character and less 20 character", "Warning", JOptionPane.WARNING_MESSAGE);
            return false;
        }
        return true;
//        else{
//            pattern = Pattern.compile(FullName_Pattern);
//            matcher = pattern.matcher(fullName);
//            return matcher.matches();
//        }
    }
     public boolean validateUserName(String userName){
        if(userName.length() < 5 || userName.length() > 20){
            JOptionPane.showMessageDialog(null, "User name must than 5 character and less 20 character", "Warning", JOptionPane.WARNING_MESSAGE);
            return false;
        }
        return true;
//        else{
//            pattern = Pattern.compile(FullName_Pattern);
//            matcher = pattern.matcher(fullName);
//            return matcher.matches();
//        }
    }
     public boolean validatePassword(String pass){
        if(pass.length() < 5 || pass.length() > 30){
            JOptionPane.showMessageDialog(null, "User name must than 5 character and less 30 character", "Warning", JOptionPane.WARNING_MESSAGE);
            return false;
        }
        return true;
//        else{
//            pattern = Pattern.compile(FullName_Pattern);
//            matcher = pattern.matcher(fullName);
//            return matcher.matches();
//        }
    }
     
     public boolean validateBirthday(String birthday){
        if(birthday.contains("Select")){
            JOptionPane.showMessageDialog(null, "You must choose day,month,year", "Warning", JOptionPane.WARNING_MESSAGE);
            return false;
        }
        return true;
//        else{
//            pattern = Pattern.compile(FullName_Pattern);
//            matcher = pattern.matcher(fullName);
//            return matcher.matches();
//        }
    }
    
     public boolean validateGender(int gender){
         if(gender == -1){
            JOptionPane.showMessageDialog(null, "You must choose gender", "Warning", JOptionPane.WARNING_MESSAGE);
            return false;
        }
        return true;
     }
     
}
